package com.xinli.business.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xinli.business.domain.TTxSq;
import com.xinli.business.service.ITTxSqService;
import com.xinli.common.utils.DateUtils;
import com.xinli.common.utils.SecurityUtils;
import com.xinli.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xinli.common.annotation.Log;
import com.xinli.common.core.controller.BaseController;
import com.xinli.common.core.domain.AjaxResult;
import com.xinli.common.enums.BusinessType;

import com.xinli.common.utils.poi.ExcelUtil;
import com.xinli.common.core.page.TableDataInfo;

/**
 * 提现申请Controller
 *
 * @author ruoyi
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/business/txsq")
public class TTxSqController extends BaseController
{
    @Autowired
    private ITTxSqService tTxSqService;

    /**
     * 查询提现申请列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TTxSq tTxSq)
    {
        startPage();
        List<TTxSq> list = tTxSqService.selectTTxSqList(tTxSq);
        return getDataTable(list);
    }

    /**
     * 导出提现申请列表
     */
    @Log(title = "提现申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTxSq tTxSq)
    {
        List<TTxSq> list = tTxSqService.selectTTxSqList(tTxSq);
        ExcelUtil<TTxSq> util = new ExcelUtil<TTxSq>(TTxSq.class);
        util.exportExcel(response, list, "提现申请数据");
    }

    /**
     * 获取提现申请详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tTxSqService.selectTTxSqById(id));
    }

    /**
     * 新增提现申请
     */
    @Log(title = "提现申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTxSq tTxSq)
    {
        return toAjax(tTxSqService.save(tTxSq));
    }

    /**
     * 修改提现申请
     */
    @Log(title = "提现申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTxSq tTxSq)
    {
        return toAjax(tTxSqService.updateById(tTxSq));
    }

    /**
     * 删除提现申请
     */
    @Log(title = "提现申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tTxSqService.removeByIds(Arrays.asList(ids)));
    }



    /**
     * @Author:zhaoyongke
     * @Description:
     */
    @PostMapping("checkXx")
    @Transactional
    public AjaxResult checkXx(@RequestBody TTxSq vo)
    {
        String checkStatus = vo.getCheckStatus();
        String checkRemark = vo.getCheckRemark();
        String id = vo.getId();
        if(StringUtils.isEmpty(id)){
            return  AjaxResult.error("参数获取失败");
        }
        if("3".equals(checkStatus)  && StringUtils.isEmpty(checkRemark)){
            return  AjaxResult.error("请填写审核备注");
        }
        TTxSq txjl = tTxSqService.getById(id);
        txjl.setCheckStatus(checkStatus);
        txjl.setCheckDate(DateUtils.getNowDate());
        txjl.setCheckUser(SecurityUtils.getUserId()+"");
        txjl.setCheckRemark(checkRemark);
        return toAjax(tTxSqService.updateById(txjl));
    }
}
